<?php
	include("config.inc.php");
	if($_GET["act"] == "cp") {
		$newdir = $dir.$_POST["dir"]."/";
		$uploadfile = $newdir . basename($_POST["img_url"]);
		$img = file_get_contents($_POST["img_url"]);
		$f = @fopen($uploadfile,"wb");
		if(!$f) die("wrong file!");
		fwrite($f,$img);
		fclose($f);
		header("Location:index.php?dir=".$_POST["dir"]);
	}
	if($_GET["act"] == "do") {
		$newdir = $dir.$_POST["dir"]."/";
		$uploadfile = $newdir . basename($_FILES['file']['name']);
		if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
			header("Location:index.php?dir=".$_POST["dir"]);
		} else {
			die("wrong!");
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <title>upload picture</title>
  <meta name="title" content="MG2 demo gallery" />
  <meta name="robots" content="noindex,nofollow" />
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <link href="style.css" rel="stylesheet" type="text/css"></link>
</head>
<body class="photosbody">
<div class="headnav">
<table width="100%">
<tr>
<td>
<?php
   include("../header.php");

?>
</td>
</tr>
</table>
</div>
<div class="import1">
<table cellspacing="0" cellpadding="0" class="table-headline" width="80%">
<tr>
  <td class="iconbar">upload photos</td>
  <td class="headline">JunYe Photos </td>
</tr>
</table>
</div>
<br />
<div class="introtext">
  <h2>upload photo online</h2>
  <form name="form1" enctype="multipart/form-data" method="post" action="upload.php?act=do">
<?php
	$dir_arr = explode("/",$_GET["dir"]);
	$dir_str =  "/";
	for($i=0;$i<count($dir_arr);$i++) {
		if($i!=0) $dir_url .= "/";
		$dir_url .= $dir_arr[$i];
		$dir_str .= $dir_arr[$i];
		if($i!=0) $dir_str .= "/";
	}
?>
	  <strong>on [<?php echo $dir_str; ?>] this cataloge upload the photos</strong><br />
<input type="file" name="file" size="20" >
<input type="hidden" name="MAX_FILE_SIZE" value="5000"> 
<input type="hidden" name="dir" value="<?php echo $_GET["dir"]; ?>" />
<input type="submit" value="upload" > 
</form>
<form name="form2" method="post" action="upload.php?act=cp">

<br />

<strong>on [<?php echo $dir_str; ?>] this cataloge upload the photos</strong><br />
<input type="text" name="img_url" />
<input type="hidden" name="dir" value="<?php echo $_GET["dir"]; ?>" />
<input type="submit" value="uploadwithURL" > 
<br />
	you can upload any pictures with it's URL on your computer.
</form>
</div>

</body>
</html>

